package com.woniuxy.course.service.impl;

import com.woniuxy.commons.entity.CourseChapter;
import com.woniuxy.commons.entity.Courseware;
import com.woniuxy.commons.exception.course.CoursewareNotFoundException;
import com.woniuxy.course.mapper.CourseChapterMapper;
import com.woniuxy.course.service.CourseChapterService;
import org.mybatis.spring.MyBatisSystemException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;

/**
 * @Author LuoChen
 * @DateTime 2020-08-03 09:55:52
 * @Description
 */
@Service
public class CourseChapterServiceImpl implements CourseChapterService {

    @Autowired
    private CourseChapterMapper courseChapterMapper;

    /**
     * 根据章节id查找课件
     * @param cpid
     * @return: java.util.List<com.woniuxy.commons.entity.Courseware>
     * @author: LuoChen
     * @dateTime: 2020-08-03 09:54:11
     */
    @Override
    public List<Courseware> findCoursewareByCpid(int cpid) {
        try {
            return courseChapterMapper.findCoursewareByCpid(cpid);
        }catch (Exception e){
            throw new CoursewareNotFoundException("查询出错");
        }

    }

    /**
     * 根据课程id查找章节
     * @param cid
     * @return: java.util.List<com.woniuxy.commons.entity.CourseChapter>
     * @author: LuoChen
     * @dateTime: 2020-08-03 17:47:54
     */
    @Override
    public List<CourseChapter> findChaptersByCid(int cid) {
        return courseChapterMapper.findChaptersByCid(cid);
    }
}
